'''
Created on 2009-12-2

@author: Madlee
'''

import wx
from wx import glcanvas
from OpenGL.GL import *
from OpenGL.GLUT import *


GL_IS_PAINTING = False

class Glyph:
    def draw(self):
        raise NotImplementedError()
    
class AtomGlyph:
    def __init__(self, atom):
        self.__atom = atom
        
    def draw(self):
        pass
        

class Mol3DPanel(glcanvas.GLCanvas):
    def __init__(self, *args, **kwargs):
        glcanvas.GLCanvas.__init__(self, *args, **kwargs)
        self.init = False
        # initial mouse position
        self.size = None
        self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
        self.Bind(wx.EVT_SIZE, self.OnSize)
        self.Bind(wx.EVT_PAINT, self.OnPaint)

    def OnEraseBackground(self, event):
        pass # Do nothing, to avoid flashing on MSW.


    def OnSize(self, event):
        size = self.size = self.GetClientSize()
        if self.GetContext():
            self.SetCurrent()
            glViewport(0, 0, size.width, size.height)
        event.Skip()


    def OnPaint(self, event):
        dc = wx.PaintDC(self)
        self.SetCurrent()
        if not self.init:
            self.InitGL()
            self.init = True
        self.OnDraw()
        self.SwapBuffers()
        
    def InitGL(self):
        # set viewing projection
        glMatrixMode(GL_PROJECTION)
        glFrustum(-0.5, 0.5, -0.5, 0.5, 1.0, 3.0)

        # position viewer
        glMatrixMode(GL_MODELVIEW)
        glTranslatef(0.0, 0.0, -2.0)

        # position object
        # glRotatef(self.y, 1.0, 0.0, 0.0)
        # glRotatef(self.x, 0.0, 1.0, 0.0)

        glEnable(GL_DEPTH_TEST)
        glEnable(GL_LIGHTING)
        glEnable(GL_LIGHT0)

    def OnDraw(self):
        # clear color and depth buffers
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

if __name__ == '__main__':
    app = wx.PySimpleApp()
    frame = wx.Frame(None, -1)
    panel = Mol3DPanel(frame)
    frame.Show()
    app.MainLoop()

